package com.lyh.hkcloud.module.m1300087;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.*;
import com.lyh.hkcloud.R;
import com.lyh.hkcloud.activity.HomeActivity;
import com.lyh.hkcloud.base.BaseActivity;
import com.lyh.hkcloud.constants.BusinessConstants;
import com.lyh.hkcloud.constants.HttpUrlComstants;
import com.lyh.hkcloud.module.m1300087.adapter.ListViewAdapter;
import com.lyh.hkcloud.module.m1300087.service.Service;
import com.lyh.hkcloud.util.base.JsonUtil;
import com.lyh.hkcloud.util.base.ToastUtils;
import com.lyh.hkcloud.util.http.listener.json.JsonFailuredListener;
import com.lyh.hkcloud.util.http.listener.json.JsonSuccessListener;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;



/**
 * @author: zhongfan
 * @program: hkCloud
 * @description:创建单据
 * @company—date: 利元数据 2022-02-16 10:04
 **/
public class IndexActivity extends BaseActivity implements View.OnClickListener, ListViewAdapter.DeleteCallback {

    private ImageView go_back;
    private TextView tv_psncode;
    private TextView tv_psnname;
    private TextView tv_plant;
    private TextView tv_type;
    private TextView tv_physicalcode;
    private TextView tv_assetsnumber;
    private TextView tv_cardname;
    private TextView tv_eqnum;
    private TextView tv_manum;
    private TextView tv_maname;
    private TextView tv_num;
    private TextView tv_meins;
    private TextView tv_comname;

    private Service service;

    @Override
    public void onClick(View v) {

    }

    @Override
    protected Activity getActivity() {
        return this;
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_1300087;
    }

    @Override
    protected int getSubmitResId() {
        return R.id.bt_save;
    }

    @Override
    protected int getClearResId() {
        return R.id.bt_cancel;
    }

    @Override
    protected void initView() {
        go_back = findViewById(R.id.go_back);
        tv_psncode = findViewById(R.id.tv_psncode);
        tv_psnname = findViewById(R.id.tv_psnname);
        tv_plant = findViewById(R.id.tv_plant);
        tv_type = findViewById(R.id.tv_type);
        tv_physicalcode = findViewById(R.id.tv_physicalcode);
        tv_assetsnumber = findViewById(R.id.tv_assetsnumber);
        tv_cardname = findViewById(R.id.tv_cardname);
        tv_eqnum = findViewById(R.id.tv_eqnum);
        tv_manum = findViewById(R.id.tv_manum);
        tv_maname = findViewById(R.id.tv_maname);
        tv_num = findViewById(R.id.tv_num);
        tv_meins = findViewById(R.id.tv_meins);
        tv_comname = findViewById(R.id.tv_comname);
        getSupportActionBar().hide();
    }

    @Override
    protected void initEvent() {

        go_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(IndexActivity.this, com.lyh.hkcloud.module.m1300030.IndexActivity.class);
                IndexActivity.this.startActivity(intent);
            }
        });
    }

    @Override
    public void deletePosition(int saveposition) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            this.queryAssetType();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onBeginInit() {
        service = new Service(IndexActivity.this);
    }

    @Override
    protected void onSubmit() {

    }


    private void queryAssetType() throws JSONException {
        Intent intent=getIntent();
        String id=intent.getStringExtra(BusinessConstants.BILL_NUMBER);
        JSONObject inDto=new JSONObject();
        inDto.put(BusinessConstants.ID,id);
        service.post(inDto, HttpUrlComstants.GET_FA_RECORD_DETAIL, new JsonSuccessListener() {
            @Override
            public void onRespone(String msg, JSONObject response) {
                try {
                    JSONArray result = JsonUtil.getJsonObjectArray(response, "result", IndexActivity.this);
                    if(null!=result&&result.length()>0){
                        JSONObject detail=result.getJSONObject(0);
                        tv_physicalcode.setText(detail.getString("physicalcode"));
                        tv_num.setText(detail.getString("num"));
                        tv_comname.setText(detail.getString("comname"));
                        tv_psncode.setText(detail.getString("psncode"));
                        tv_type.setText(detail.getString("type"));
                        tv_psnname.setText(detail.getString("psnname"));
                        tv_maname.setText(detail.getString("maname"));
                        tv_cardname.setText(detail.getString("cardname"));
                        tv_plant.setText(detail.getString("plant"));
                        tv_meins.setText(detail.getString("meins"));
                        tv_assetsnumber.setText(detail.getString("assetsnumber"));
                        tv_eqnum.setText(detail.getString("eqnum"));
                        tv_manum.setText(detail.getString("manum"));
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new JsonFailuredListener() {
            @Override
            public void onRespone(String msg, JSONObject response) {
                Log.e("error", response.optString("message"));
                ToastUtils.makeText(IndexActivity.this, msg, ToastUtils.LENGTH_SHORT).show();
            }
        });
    }
}
